package hd.cls5;

import java.io.File;

/**
 * @author oldliu
 * @since 1.0
 */
public class FileSize {
    public static long getFileSize(File file) {
        if (file == null && !file.canRead())
            return 0;
        if (file.isFile())//不是文件夹
            return file.length();

        long total = 0;
        File[] fr = file.listFiles();
        for (File f : fr) {
            total += getFileSize(f);//!!!!!!!
        }
        return total;
    }

    public static void main(String[] args) {
        String folder = "E:\\信诺100";
        long fileSize = getFileSize(new File(folder));
        System.out.println("大小：" + fileSize);
    }
}
